package com.bitrate.dagger.gateway.xss;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class JsonXssClean extends JsonDeserializer<String> {

	private final XssCleaner xssCleaner;

	@Override
	public String deserialize(JsonParser parser, DeserializationContext context) throws IOException {
		String text = parser.getValueAsString();
		if (text == null) {
			return null;
		}
		return xssCleaner.clean(text);
	}

}